{include file='public/header' /}

<body>

<div class="x-nav">

  <span class="layui-breadcrumb">

      <a href="">首页</a>

      <a href="">预约订单管理</a>

      <a><cite>预约订单列表</cite></a>
  </span>

  <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">

      <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>

  </a>

</div>





<div class="x-body">



    <table class="layui-hide" id="test" lay-filter="test"></table>

   

</div>





<script type="text/html" id="toolbarDemo">

      <div class="layui-form-item"> 

        <form class="layui-form" action="" lay-filter="search">

           <div class="layui-input-inline">

                  <select name="status">
                      <option value="">全部状态</option>

                      <option value="1">待付款</option>

                      <option value="2">已付款</option>

                      <option value="3">检测中</option>

                      <option value="4">已完成</option>
                  </select>

          </div>



          <div class="layui-input-inline">

                  <select name="staff_id">
                      <option value="">全部员工</option>
                      {foreach $stafflist as $x}
                      <option value="{$x.id}">{$x.name}</option>
                      {/foreach}
                  </select>

          </div>




          <div class="layui-input-inline" style="width:20%;">
            <input type="text" class="layui-input test" name="create_time"  autocomplete="off" placeholder="时间段搜索" id="test1">
          </div>



           <input type="text"  placeholder="请输入搜索内容" autocomplete="off" class="layui-btn layui-btn-primary" name="keywords">

            <div class="layui-inline">
              <button class="layui-btn"  lay-event="searchBarFunc"><i class="layui-icon">&#xe615;</i></button>
            </div>  
        </form>
      </div>
</script>



<script type="text/html" id="barDemo">

  <div class="layui-btn-container">

      {if $qxarr['look']}
      <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" lay-event="look">查看</button>
      {/if}


      {{#  if(d.status == 2){ }}
      {if $qxarr['edit']}
      <button type="button" class="layui-btn layui-btn-sm" lay-event="edit">分配员工</button>
      {/if}
      {{#  } }}
      
      {{#  if((d.status == 2 || d.status == 3) && d.refund_status <= 0){ }}
      <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" lay-event="refund">退款</button>
      {{#  } }}

  </div>




</script>



<script type="text/html" id="status">

    {{#  if(d.status == 1){ }}

      <span class="layui-btn layui-btn-danger layui-btn-xs">待支付</span>

    {{#  } }}


    {{#  if(d.status == 2){ }}

      <span class="layui-btn  layui-btn-xs">已支付</span>

    {{#  } }}


    {{#  if(d.status == 3){ }}

      <span class="layui-btn  layui-btn-xs layui-btn-warm">检测中</span>

    {{#  } }}


    {{#  if(d.status == 4){ }}

      <span class="layui-btn  layui-btn-xs layui-btn-normal">已完成</span>

    {{#  } }}
    
    {{#  if(d.status == 5){ }}

      <span class="layui-btn  layui-btn-xs layui-btn-disabled">已退款</span>

    {{#  } }}


</script>



<script type="text/html" id="address">

    {{d.province}}-{{d.city}}-{{d.county}}

</script>



<script type="text/html" id="sid">

    {{#  if(d.serviceinfo){ }}

      {{d.serviceinfo.name}}
     
    {{#  } }}

</script>




<script type="text/html" id="staff">

    {{#  if(d.staffinfo){ }}

      {{d.staffinfo.name}}
     
    {{#  } }}

</script>

<script type="text/html" id="refund_status">
    {{#  if(d.refund_status == 10){ }}
        <span class="layui-btn layui-btn-danger layui-btn-xs">退款中</span>
    {{#  } else if(d.refund_status == 100){ }}
        <span class="layui-btn layui-btn-success layui-btn-xs">已退款</span>
    {{# }else{ }}
        <span class="layui-btn layui-btn-disabled layui-btn-xs">未退款</span>
    {{# } }}
</script>




<style type="text/css">

  /*{# 设置table每一行的height #}*/

  .layui-table-cell {

   height: 50px;

   line-height: 50px;

  }

 </style>





<script>

layui.use(['table','laydate'], function(){

  var table = layui.table

  ,form = layui.form
  ,laydate = layui.laydate;

        laydate.render({
          elem: '#test1'
          ,type: 'datetime'
          ,range: true
        });

  //第一个实例

  table.render({

    elem: '#test'

    ,height:'full-100'

    ,title:'预约订单列表'

    ,url: "{:url('gList')}" //数据接口

    ,page: true //开启分页

    ,limit:30

    ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板

    ,cols: [[ //表头

       {field: 'code', title: '订单编号'}

      ,{field: 'sid', title: '服务项目',templet: '#sid'}

      ,{field: 'brand', title: '品牌'}

      ,{field: 'model', title: '车型'}

      ,{field: 'address', title: '检测地址',templet: '#address'}

      ,{field: 'status', title: '支付结果',templet: '#status'}
      
      ,{field: 'status', title: '退款状态',templet: '#refund_status'}

      ,{field: 'staff_id', title: '分配员工',templet: '#staff'}

      ,{field: 'create_time', title: '下单时间'}

      ,{fixed: 'right', title:'操作', width: 220,toolbar: '#barDemo'}

    ]],done: function(res, curr, count) {
   
              laydate.render({
                        elem: '#test1'
                        ,type: 'datetime'
                        ,range: true
                      });
            }


  });



  //监听行工具事件

  table.on('tool(test)', function(obj){

    var data = obj.data;

    //console.log(obj)

    if(obj.event === 'look'){
      x_admin_show('查看预约订单信息',"{:url('look')}?id="+data.id);
    }else if(obj.event === 'refund'){
        layer.confirm('单号('+ data.code +')确认退款？', {
            btn: ['确定', '关闭'],
            title: '提示'
          }, function(){
            var loading = layer.load(0, {shade: false});
            $.ajax({
                url:'{:url("order/refund")}', 
                data:{id:data.id},
                dataType: 'json',
                type:'POST',
                success: function(data){
                    if(data.code==0){
                        layer.msg(data.msg, {icon: 1} , function(){
                            table.reload('test');
                        });
                    }else{
                        layer.msg(data.msg, {icon: 2}); 
                    }
                },
                complete: function(){
                    layer.close(loading);
                },
                error: function(){
                    layer.msg('请求失败,请重试', {icon: 0});
                }
            })
          }, function(index){
            layer.close(index);
        });
    }else{
      x_admin_show('分配员工',"{:url('edit')}?id="+data.id);
    }

  });



 //头工具栏事件

  table.on('toolbar(test)', function(obj){

       if(obj.event === 'searchBarFunc'){

              var data = form.val('search');
            
              table.reload('test',{
                  url: "{:url('gList')}",

                  page: {
                    curr: 1 //重新从第 1 页开始
                  }

                 ,where: data
                 ,done: function(res, curr, count){
                    form.val('search', data);

                     //日期范围
                      laydate.render({
                        elem: '#test1'
                        ,type: 'datetime'
                        ,range: true
                      });

                 }
              })


        }

  });



  

});

</script>











</body>

</html>